package com.jsgt.greekfire.ui.mine.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.fhx.core.utils.PriceFormatUtil
import com.jsgt.greekfire.MONEY_SCALE
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.AssetsBean

/**
 * 资产列表
 */
class AssetsAdapter : BaseAdapter<AssetsBean>() {


    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var icon_tv: ImageView? = null
        var coin_name_tv: TextView? = null
        var balance_tv: TextView? = null
        var dollar_tv: TextView? = null

        init {
            icon_tv = itemView.findViewById(R.id.icon_tv)
            coin_name_tv = itemView.findViewById(R.id.coin_name_tv)
            balance_tv = itemView.findViewById(R.id.balance_tv)
            dollar_tv = itemView.findViewById(R.id.dollar_tv)
        }

        fun bindData(bean: AssetsBean) {
            var sum = ""
            coin_name_tv?.text = bean.assetName
            when (bean.assetGuid) {
                "1" -> {
                    sum = PriceFormatUtil.format((bean.assetBalance!!+bean.assetFrozen!!) * 0.1 * MONEY_SCALE, 4)
                    icon_tv?.setImageResource(R.mipmap.icon_glb)
                }
                "2" -> {
                    sum = PriceFormatUtil.format((bean.assetBalance!!+bean.assetFrozen!!) * MONEY_SCALE, 4)
                    icon_tv?.setImageResource(R.mipmap.icon_usdt)
                }
//                "3" -> {
//                    sum = PriceFormatUtil.format((bean.assetBalance!!+bean.assetFrozen!!) * MONEY_UTIT_SCALE * MONEY_SCALE, 4)
//                    icon_tv?.setImageResource(R.mipmap.icon_gft)
//                }
//                "4"->{
//                    sum = PriceFormatUtil.format((bean.assetBalance!!+bean.assetFrozen!!) * MONEY_UTIT_SCALE * MONEY_SCALE, 4)
//                    icon_tv?.setImageResource(R.mipmap.icon_ut)
//                }
            }
            balance_tv?.text = PriceFormatUtil.format((bean.assetBalance!!+bean.assetFrozen!!), 4)

            dollar_tv?.text = "=¥\t${sum}"
        }
    }

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_assets, parent, false)
        return VH(view)
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }
}
